import { createApp } from 'vue'

import { createPinia } from 'pinia'
import piniaPluginPersistedstate from 'pinia-plugin-persistedstate'

import { install as permissionInstall } from './directives/permission'

// 添加这行导入语句 - 根据实际路径调整
import { usePermissionStore } from './stores/permission'

import App from './App.vue'

import router from './router/index'

import http from '@/utils/http';

import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
// @ts-ignore
import zhCn from 'element-plus/dist/locale/zh-cn.mjs'

const app = createApp(App)

app.use(permissionInstall)

// 注册所有图标
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component)
}

const pinia = createPinia()
pinia.use(piniaPluginPersistedstate)

app.config.globalProperties.$http = http;

app.use(ElementPlus, {
  locale: zhCn,
})
app.use(pinia)
app.use(router)

// 确保在mount之前初始化权限store
//const permissionStore = usePermissionStore()
usePermissionStore()
// 如果需要初始化权限数据，可以在这里调用相关方法
// permissionStore.initPermissions()


// 初始化动态路由
app.mount('#app')
